package indi.kider.server.bill.api;

import indi.kider.common.constant.EmployeeRoleCons;
import indi.kider.common.model.bill.RentBill;
import indi.kider.common.model.employee.Employee;
import indi.kider.server.bill.service.BillService;
import indi.kider.server.bill.service.related.AuthcService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.io.InputStreamResource;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;

@RestController
@RequestMapping("excel")
public class ExcelEportController {
    //查询账单
    //自动模式结算
    @Autowired
    private BillService billService;
    @Autowired
    private AuthcService authcService;

    /**
     * @api {POST} excel/bill/rent/list
     * @apiGroup balance-bill
     * @apiDescription 查询账单导出
     * @apiParamExample 请求样例：
     * http://localhost:9002/balance-bill/excel/bill/rent/list
     * query":{"communityId":-1,"housesId":-1,"billType":-1,"payState":-1,"expression":""}
     * @apiSuccessExample {json} 返回样例:
     * 文件
     **/
    @PostMapping(value = "bill/rent/list")
    public ResponseEntity<InputStreamResource> exportRentBill(@RequestBody RentBill rentBill) throws IOException {
        Employee employee = authcService.getCurrentUser().getData();
        if (employee != null && !employee.getRoles().equals(EmployeeRoleCons.ADMIN)) {//超级管理员
            rentBill.setEnterpriseId(employee.getEnterpriseId());
        }
        return billService.exportRentBill(rentBill);
    }
}
